<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="common :: commonHead('验证公共静态资源的引入')">
    <meta charset="UTF-8">
    <title>index页面模板</title>
</head>
<body>
<div id="toolbar">
    <form class="form-inline">
       <!-- <div class="form-group">
            <label for="indentId">订单编号</label>
            <input type="text" class="form-control" id="indentId" name="indentId" placeholder="请输入订单编号">
        </div>
        <div class="form-group">
            <label for="indentId">设备编号</label>
            <input type="text" class="form-control" id="facilityId" name="facilityId" placeholder="请输入设备编号">
        </div>
        <div class="form-group">
            <label for="indentId">手机号</label>
            <input type="text" class="form-control" id="phone" name="phone" placeholder="请输入手机号">
        </div>
        <div class="form-group">
            <label for="indentStart">订单状态</label>
            <select class="form-control" id="indentStart">
                <option value="">请选择</option>
                <option value="已付款">已付款</option>
                <option value="未付款">未付款</option>

            </select>
        </div>
        <div class="form-group">
            <label for="payWay">支付方式</label>
            <select class="form-control" id="payWay">
                <option value = "">请选择</option>
                <option value = "微信">微信</option>
                <option value = "支付宝">支付宝</option>
            </select>
        </div>
        <div class="form-group">
            <label for="indentId">创建时间</label>
            <input type="date" class="form-control" id="startDate" placeholder="开始时间">
        </div>
        <div class="form-group">
            <label for="indentId">-</label>
            <input type="date" class="form-control" id="endDate" placeholder="结束时间">
        </div>-->

        <button type="button" class="btn btn-info glyphicon glyphicon-search" onclick="searchPlayer()">搜索</button>
        <button type="button" class="btn btn-info glyphicon glyphicon-plus" onclick="openAdd()">新增</button>
    </form>
</div>

<table class="table" id="userTable"></table>
</body>
<script type="text/javascript">
    //初始化加载
    $(function(){
        initTable();//初始化表格
    });

    //条查
    function searchPlayer(){
        $('#userTable').bootstrapTable("refresh");
    }
    //初始化表格
    function initTable(){
        $('#userTable').bootstrapTable({
            toolbar:'#toolbar',
            url:'../queryCouList',//获取数据地址  联系人列表
            pagination:true, //是否展示分页
            pageList:[2, 4, 6, 50],//分页组件
            pageNumber:1,
            pageSize:2,//默认每页条数
            sidePagination:'server',//分页方式：client客户端分页，server服务端分页（*
            striped:true,//斑马线

            queryParams:function(){
               /* var indentId = $("#indentId").val();
                var facilityId = $("#facilityId").val();
                var phone = $("#phone").val();
                var indentStart = $("#indentStart").val();
                var payWay = $("#payWay").val();
                var startDate = $("#startDate").val();
                var endDate = $("#endDate").val();*/

                return {
                   /* indentId: indentId,
                    facilityId:facilityId,
                    phone:phone,
                    indentStart:indentStart,
                    payWay: payWay,
                    startDate:startDate,
                    endDate:endDate,*/

                };
            },
            columns:[
                {field:'couponId',title:'编号',align:'center'},
                {field:'couponName',title:'订单编号',align:'center'},
                {field:'couponType',title:'公司',align:'center'},
                {field:'couponScope',title:'姓名',align:'center'},
                {field:'couponStarts',title:'订单金额',align:'center'},
                {field:'couponDate',title:'支付方式',align:'center'},



                {field:"tools",title:"操作",formatter:function(value,row,index){
                        var str = "";
                        str += "<button type='button' class='btn btn-info' onclick='openUpdate("+row.userId+")'>编辑</button>";
                        str += "<button type='button' class='btn btn-danger' onclick='openDelete("+row.userId+")'>删除</button>";
                        str += "<button type='button' class='btn btn-info' onclick='openUpdate("+row.userId+")'>查看</button>";
                        return str;
                    }}
            ]
        });
    }
    //删除
    function openDelete(userId){
        bootbox.confirm({
            size: "small",
            title: "提示",
            buttons: {
                confirm: {
                    label: '确定',
                    className: 'btn-success'
                },
                cancel: {
                    label: '取消',
                    className: 'btn-danger'
                }
            },
            message:"是否进行删除???",
            callback: function (result) {
                if (result) {
                    $.ajax({
                        url:"../boot/deleteUser",
                        type:"post",
                        data:{userId:userId},
                        success:function(){
                            bootbox.alert({ //没有选中
                                size: "small",
                                title: "提示",
                                message: "删除成功！！",
                            });
                            $('#userTable').bootstrapTable("refresh");
                            //searchPlayer();
                        }
                    });
                }
            }
        });
    }
    //加载页面
    var res;
    function createAddContent(url){
        $.ajax({
            url:url,
            async:false,//同步
            success:function(data){//页面
                res = data;
            }
        });
        return res;
    }

    //打开新增弹框
    function openAdd(){
        //打开弹框
        bootbox.dialog({
            title:'新增信息',
            message: createAddContent("../boot/addshow"),
            closeButton: true,//是否显示关闭按钮
            buttons : {//自定义按钮
                "success" : {//确定、保存
                    "label" : "<i class='icon-ok'></i> 保存",
                    "className" : "btn-sm btn-success",
                    "callback" : function() {
                        //保存数据
                        $.ajax({
                            url:'../boot/addUser',
                            type:'post',
                            data:$("#userForm").serialize(),
                            success:function(){
                                //刷新表格
                                $('#userTable').bootstrapTable('refresh');
                                location.href="../boot/queryUserList";

                                /* queryMessageList(); */
                                bootbox.alert({ //没有选中
                                    size: "small",
                                    title: "提示",
                                    message: "新增成功！！",
                                });
                            }
                        });
                    }
                },
                "cancel" : {//取消
                    "label" : "<i class='icon-info'></i> 取消",
                    "className" : "btn-sm btn-danger"
                }
            }
        });
    }
    //打开新增弹框
    function openUpdate(uid){
        //打开弹框
        bootbox.dialog({
            title:'修改信息',
            message: createAddContent("../boot/addshow"),
            closeButton: true,//是否显示关闭按钮
            buttons : {//自定义按钮
                "success" : {//确定、保存
                    "label" : "<i class='icon-ok'></i> 保存",
                    "className" : "btn-sm btn-success",
                    "callback" : function() {
                        //保存数据
                        $.ajax({
                            url:'../boot/addUser',
                            type:'post',
                            data:$("#userForm").serialize(),
                            success:function(){
                                //刷新表格
                                $('#userTable').bootstrapTable('refresh');


                            }
                        });
                    }
                },
                "cancel" : {//取消
                    "label" : "<i class='icon-info'></i> 取消",
                    "className" : "btn-sm btn-danger"
                }
            }
        });

        //回显
        $.ajax({
            url: "../boot/findUserById?uid=" + uid,
            type: "get",
            async: false,//同步
            success: function (data) {
                $("#userId").val(data.userId);
                $("#userAccount").val(data.userAccount);
                $("#userPwd").val(data.userPwd);

            }
        });
    }

</script>
</html>